home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / begincpp.zip / #10.CPP < prev    next >
C/C++ Source or Header  |  1990-08-05  |  433b  |  26 lines

  1. // STR_CNT.CXX : a word count program that uses stream i/o
  2.  
  3. #include <stream.hxx>
  4. #include <ctype.h>
  5.  
  6. main() 
  7. {
  8.     int word_cnt = -1;
  9.     void found_next_word (void);
  10.     
  11.     while ( cin.good() ) {    // ^Z ends input
  12.         word_cnt++;            // increment counts
  13.         found_next_word ();
  14.     }    
  15.     cout << "word count is " << word_cnt << "\n";
  16. }
  17.  
  18. void found_next_word (void)
  19. {
  20.     char c;
  21.     
  22.     cin >> c;
  23.     while (!isspace (c))
  24.         cin.get (c);
  25. }
  26.